package com.vctgo.certificate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.certificate.domain.TbCertificate;
import com.vctgo.certificate.service.ITbCertificateService;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 凭证字Controller
 *
 * @author vctgo
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/certificate")
public class TbCertificateController extends BaseController
{
    @Autowired
    private ITbCertificateService tbCertificateService;

    /**
     * 查询凭证字列表
     */
    @RequiresPermissions("certificate:certificate:list")
    @GetMapping("/list")
    public AjaxResult list(TbCertificate tbCertificate)
    {
        IPage<TbCertificate> list = tbCertificateService.selectTbCertificatePage(tbCertificate);
        return AjaxResult.success(list);
    }

    /**
     * 导出凭证字列表
     */
    @RequiresPermissions("certificate:certificate:export")
    @Log(title = "凭证字", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCertificate tbCertificate)
    {
        List<TbCertificate> list = tbCertificateService.selectTbCertificateList(tbCertificate);
        ExcelUtil<TbCertificate> util = new ExcelUtil<TbCertificate>(TbCertificate.class);
        util.exportExcel(response, list, "凭证字数据");
    }

    /**
     * 获取凭证字详细信息
     */
    @RequiresPermissions("certificate:certificate:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCertificateService.selectTbCertificateById(id));
    }

    /**
     * 新增凭证字
     */
    @RequiresPermissions("certificate:certificate:add")
    @Log(title = "凭证字", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCertificate tbCertificate)
    {
        return toAjax(tbCertificateService.insertTbCertificate(tbCertificate));
    }

    /**
     * 修改凭证字
     */
    @RequiresPermissions("certificate:certificate:edit")
    @Log(title = "凭证字", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCertificate tbCertificate)
    {
        return toAjax(tbCertificateService.updateTbCertificate(tbCertificate));
    }

    /**
     * 删除凭证字
     */
    @RequiresPermissions("certificate:certificate:remove")
    @Log(title = "凭证字", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCertificateService.deleteTbCertificateByIds(ids));
    }
}
